package com.cy.java.api.reflect;
//模拟启动类的底层动作

import java.io.File;
import java.net.URL;

public class PackageTests {
    public static void main(String[] args) {
        Class<?> c = PackageTests.class;
        Package apackage = c.getPackage();
        String name = apackage.getName();
        System.out.println(name);//com.cy.java.api.reflect
        //将包结构转换为目录结构
        String dirName = name.replace(".", "/");
        System.out.println(dirName);//com/cy/java/api/reflect
        URL url=
        ClassLoader.getSystemClassLoader().getResource(dirName);
        //获取路径对应的文件File对象
        File file = new File(url.getPath());
        //获取目录下的文件名
        String files[] = file.list();
        for (String f:files) {
            System.out.println(f);
        }
    }
}
